package com.uniledger.test.model;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import io.reactivex.Flowable;
import io.reactivex.Single;

import static android.arch.persistence.room.OnConflictStrategy.REPLACE;

@Dao
public interface SeeleAdminDao {

    /**
     * 根据用户ID获取
     *
     * @param uid
     * @return
     */
    @Query("SELECT * FROM SeeleAdmin WHERE uid=:uid")
    public Flowable<SeeleAdmin> loadAdmin(long uid);

    @Query("SELECT * FROM SeeleAdmin WHERE isSignIn=1")
    public Single<SeeleAdmin> loadAdmin();

    /**
     * 查询数量
     *
     * @return
     */
    @Query("SELECT COUNT(uid) FROM SeeleAdmin")
    public Flowable<Long> getCount();

    @Insert(onConflict = REPLACE)
    long insert(SeeleAdmin admin);

    @Delete
    int delete(SeeleAdmin admin);

    /**
     * 更新用户
     *
     * @param admin
     * @return
     */
    @Update(onConflict = REPLACE)
    int update(SeeleAdmin admin);

    /**
     * 当前用户是否锁屏，创建PIN
     *
     * @param uid
     * @param isLockPin
     * @param pin
     * @return
     */
    @Query("UPDATE SeeleAdmin SET isLockPin=(:isLockPin) , pin=(:pin) WHERE uid=(:uid)")
    int update(long uid, boolean isLockPin, String pin);

    /**
     * 当前用户的是否拥有钱包
     *
     * @param uid
     * @param walletFlag
     * @return
     */
    @Query("UPDATE SeeleAdmin SET walletFlag=(:walletFlag) WHERE uid=(:uid)")
    int update(long uid, int walletFlag);


    @Query("DELETE FROM SeeleAdmin")
    void deleteAdmin();


}
